﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CommandLine;
using CommandLine.Text;

namespace AutomatedTP
{
    /// <summary>
    /// Class for parsing parameters from command line. 
    /// Here you can see help message.
    /// -----------------------------------------------
    /// Usage of AutomatedTP
    /// For more information contact me Majlik@mail.muni.cz
    ///             
    /// Required parameter:
    ///   -s, --source      Specify names of source test cases, separated by a colon.
    ///   
    /// Optional parameters:
    ///   -l, --log         Set log level [1..3].
    ///   -c, --coverage    Set code coverage level [A, B, C, D].
    ///   -m, --manual      Generate only test harness.
    ///   -v, --verbose     Write information into console
    ///   -h, --help        Show this help message.
    /// </summary>
    class Options
    {

        public bool help = false;
        private char c_level;

        [OptionList('s', "source", Separator = ':', HelpText = "Specify names of source test cases, separated by a colon.")]
        public IList<string> Items { get; set; }

        [Option('l', "log", DefaultValue = 3, HelpText = "Set log level [1..3].")]
        public int Log { get; set; }

        [Option('c', "coverage", DefaultValue = 'D', HelpText = "Set code coverage level [A, B, C, D]")]
        public char Coverage 
        {
            get { return c_level; }
            set 
            {
                if (value > 64 && value < 69)
                {
                    c_level = value;
                }
                else { c_level = 'D'; }
            } 
        }

        [Option('v', "verbose", DefaultValue = false, HelpText = "Write information into console")]
        public bool verbose { get; set; }

        [Option('m', "manual", DefaultValue = false, HelpText = "Generate only test harness")]
        public bool Manual { get; set; }        

        [HelpOption]
        public string GetUsage()
        {
            help = true;
            var usage = new StringBuilder();
            usage.AppendLine("Usage of AutomatedTP");            
            usage.AppendLine("For more information contact me Majlik@mail.muni.cz");
            usage.AppendLine("");
            usage.AppendLine("Required parameter:");
            usage.AppendLine("");
            usage.AppendLine("  -s, --source      Specify names of source test cases, separated by a colon.");
            usage.AppendLine("");
            usage.AppendLine("Optional parameters:");
            usage.AppendLine("");
            usage.AppendLine("  -l, --log         Set log level [1..3].");
            usage.AppendLine("");
            usage.AppendLine("  -c, --coverage    Set code coverage level [A, B, C, D].");
            usage.AppendLine("");
            usage.AppendLine("  -m, --manual      Generate only test harness.");
            usage.AppendLine("");
            usage.AppendLine("  -v, --verbose     Write information into console");
            usage.AppendLine("");
            usage.AppendLine("  -h, --help        Show this help message.");
            return usage.ToString();
        }
    }
}
